package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.CourseRating;
import com.hs.service.CourseRatingService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("courserating")
public class CourseRatingController {
    @Autowired
    private CourseRatingService courseRatingService;
    @DeleteMapping("{id}")
    public R deletecourserating(@PathVariable("id") Integer id) {
        int i = courseRatingService.deleteById(id);
        if (i > 0) {
            return R.ok("操作成功");
        }else{
            return R.fail("操作失败");
        }
    }
    @PostMapping("add")
    public R addcourserating(@RequestBody CourseRating courseRating) {
        int i = courseRatingService.insertCourseRating(courseRating);
        if (i > 0) {
            return R.ok("操作成功");
        }else{
            return R.fail("操作失败");
        }
    }
    @PutMapping("update")
    public R updatecourserating(@RequestBody CourseRating courseRating) {
        int i = courseRatingService.updateCourseRating(courseRating);
        if (i > 0) {
            return R.ok("操作成功");
        }else{
            return R.fail("操作失败");
        }
    }
    @GetMapping("{id}")
    public R getcourseratingByid(@PathVariable("id") Integer id) {
        CourseRating cc = courseRatingService.selectCourseRatingById(id);
        return R.ok(cc);
    }
    @GetMapping("page")
    public R getcourseratingByPage(@RequestParam(defaultValue = "1",required = false)int pageNum,
                                   @RequestParam(defaultValue = "2",required = false)int pageSize){
        PageInfo<CourseRating> cc = courseRatingService.selectCourseRatingByPage(pageNum, pageSize);
        return R.ok(cc);
    }
}
